package com.gin.kotlin.no_gay_alliance.provider.ngaphp

import com.gin.nga.main.NgaApi
import com.gin.nga.response.user.FollowedUser
import java.lang.ref.WeakReference

class FollowUserProvider private constructor(): AbstractCachedDataProvider<Int, List<List<FollowedUser>>, List<FollowedUser>>(
    javaType = TYPE_FACTORY.constructCollectionLikeType(List::class.java, FollowedUser::class.java),
) {
    override val dir = "FOLLOW_USER"

    override fun transform(rawData: List<List<FollowedUser>>) = rawData.flatten()

    override fun requestMethod(ngaApi: NgaApi, params: Int?) = ngaApi.followApi.list(params)

    override fun obtainRelativePath(userId: Long, params: Int?) = "${userId}_$params.json"

    companion object {
        private var instance: WeakReference<FollowUserProvider> = WeakReference(FollowUserProvider())
        fun getInstance(): FollowUserProvider = instance.get() ?: FollowUserProvider().also { instance = WeakReference(it) }
    }
}